package com.fishsticks.model;

import java.util.Date;

import com.google.android.maps.GeoPoint;

import android.location.Location;

public class ToDoItem {

	private String title, description, completed;
	private int id;
	private Date dueDate;
	private Category category;
	private GeoPoint locationPoint;

	public ToDoItem(String ttl, String desc, Date date, Category cat, GeoPoint loc, String doneYet, int ID)
	{
		title = ttl;
		description = desc;
		dueDate = date;
		category = cat;
		locationPoint = loc;
		completed = doneYet;
		id = ID;
	}

	public ToDoItem(String ttl, String desc, Date date, Category cat, GeoPoint loc, boolean complete, int ID)
	{
		title = ttl;
		description = desc;
		dueDate = date;
		category = cat;
		locationPoint = loc;
		if(complete)
			this.completed = "Y";
		else
			this.completed = "N";
		id = ID;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getDueDate() {
		return dueDate;
	}

	public int getDueDateMonth() {
		//Months are zero-based so add one to it
		return dueDate.getMonth() + 1;
	}

	public int getDueDateYear() {
		return dueDate.getYear();
	}

	public int getDueDateDate() {
		return dueDate.getDate();
	}

	public int getDueDateDay() {
		return dueDate.getDay();
	}

	public void setDueDate(Date dueDate) {
		this.dueDate = dueDate;
	}

	public void setDueDateMonth(int month) {
		//Months are zero-based so subtract one to it
		dueDate.setMonth(month-1);
	}

	public void setDueDateYear(int year) {
		dueDate.setYear(year);
	}

	public void setDueDateDate(int date) {
		dueDate.setDate(date);
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public GeoPoint getLocation() {
		return locationPoint;
	}

	public double getLatitude() {
		return locationPoint.getLatitudeE6()/1000000;
	}

	public double getLongitude() {
		return locationPoint.getLongitudeE6()/1000000;
	}

	public int getId(){
		return id;
	}


	public boolean isCompleted() {
		if(completed.equals("Y") || completed.equals("y"))
			return true;
		else
			return false;
	}

	public void setLocation(GeoPoint loc) {
		this.locationPoint = loc;
	}

	public void setLatitude(double lat) {
		GeoPoint newPoint = new GeoPoint(new Double(lat*1000000).intValue(), locationPoint.getLongitudeE6());
		locationPoint = newPoint;
	}

	public void setLongitude(double lon) {
		GeoPoint newPoint = new GeoPoint(locationPoint.getLatitudeE6(), new Double(lon*1000000).intValue());
		locationPoint = newPoint;
	}

	public void setCompleted(String status) {
		if(status.equals("Y") || status.equals("N") || status.equals("y") || status.equals("n"))
			completed = status;
	}

	public String toString() {
		return title;
	}
}
